﻿@model IEnumerable<MvcAtletIS.Models.Competitions>
@{
    ViewBag.Title = "Výsledky";
}
@section head {
    
    <!-- footable -->
    <link href="@Url.Content("~/footable/css/footable.core.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/footable/css/footable.standalone.css")" rel="stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script src="@Url.Content("~/footable/js/footable.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/footable/js/footable.sort.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("table").footable();
        });
    </script>

    <!-- Moving Boxes -->
    <link href="@Url.Content("~/Content/css/Competitions.css")" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .slider { width: 350px; }
        .slider li { width: 300px; }
    </style>
    <script src="@Url.Content("~/Scripts/jquery.movingboxes.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.movingboxes.min.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $(".slider").movingBoxes({
                startPanel: 1,      // start with this panel
                wrap: false,        // if true, the panel will infinitely loop
                buildNav: true,     // if true, navigation links will be added
                navFormatter: function () { return "&#9679;"; } // function which returns the navigation text for each panel
            });
        });
    </script>
}

<!-- ---------- AKTUALNE ---------- -->

@if (ViewBag.ActualCompetitions != null & ViewBag.ActualCompetitions.Count > 0)
{
    <div class="actual-box">
        <h3>
            Aktuálne preteky
        </h3>
        <div class="wrapper">
            <ul class="slider">
                @foreach (var item in ViewBag.ActualCompetitions)
                {
                    <li>   
                        <img src="@Url.Content("~/Content/logos/" + item.Organiser + ".png")" alt="picture" /><br />
                        <b>         @item.Name      </b><br />
                        Miesto:     @item.City      <br />
                        Dátum:      @item.DateFrom.ToShortDateString()   <br />
                        <br />
                
                        @if (!item.External)
                        {
                            @Html.ActionLink("Online výsledky", "Details", "Results", new { competitionId = item.ID }, null)
                        }
                    </li>
                }
            </ul>
        </div>
    </div>
}
else
{
    <!-- ---------- NASLEDUJUCE ---------- -->
    <div class="box">
        <h3>
            Nasledujúce preteky
        </h3>
        <div class="wrapper">
            <ul class="slider">
                @{
                    foreach (var preItem in ViewBag.NextCompetitions)
                    {
                        <li>
                            <img src="@Url.Content("~/Content/logos/" + preItem.Organiser + ".png")" alt="picture" /><br />
                            <b>         @preItem.Name       </b><br />
                            Miesto:     @preItem.City       <br />
                            Dátum:      @preItem.DateFrom.ToShortDateString()   <br />

                            @if (!preItem.External)
                            {
                                @Html.ActionLink("Zoznam prihlásených pretekárov", "List", "Signups", new { competitionId = preItem.ID }, null)<br />
                            }
                            else
                            { 
                                <br />
                            }
                        
                            @if (preItem != null)
                            {
                                if (preItem.bPropositions)
                                {
                                    string sResultPath = System.IO.Path.Combine(preItem.DateFrom.Year.ToString(), preItem.DateFrom.Month.ToString(), "PROP" + preItem.ID.ToString() + ".pdf");
                                <a href="@Url.Content("~/Content/results/" + @sResultPath)" target="_blank">
                                    Propozície
                                </a>
                                }
                            }
                        </li>
                    }
                }
            </ul>
        </div>
    </div>

    <!-- ---------- PREDCHADZAJUCE ---------- -->
    <div class="box">
        <h3>
            Predchádzajúce preteky
        </h3>
        <div class="wrapper">
            <ul class="slider">
                @{
                    foreach (var postItem in ViewBag.PreviousCompetitions)
                    { 
                        <li>
                            <img src="@Url.Content("~/Content/logos/" + postItem.Organiser + ".png")" alt="picture" /><br />
                            <b>         @postItem.Name      </b><br />
                            Miesto:     @postItem.City      <br />
                            Dátum:      @postItem.DateFrom.ToShortDateString()  <br />
                            <br />
                        
                            @if (postItem.External)
                            {
                                if (postItem.bResults)
                                {
                                    string sResultPath = postItem.DateFrom.Year.ToString() + "/" + postItem.DateFrom.Month.ToString() + "/" + "VYS" + postItem.ID.ToString() + ".pdf";
                                <a href="@Url.Content("~/Content/results/" + @sResultPath)" target="_blank">
                                    Výsledky
                                </a>
                                }
                            }
                            else
                            {
                                @Html.ActionLink("Výsledky", "Details", "Results", new { competitionId = postItem.ID }, null) 
                            }

                        </li>
                    }
                }
            </ul>
        </div>
    </div>
}

<!-- ---------- FILTER ---------- -->
<div id="next-articles">
    Prehľad pretekov
</div>

<p> 
    Vyberte rok a mesiac, pre ktorý chcete zobraziť prehľad pretekov. 
</p>

@using (Html.BeginForm())
{   
    <div class="filter-frame">
        
        <div class="filter-item">
            <div class="editor-label">
                Rok
            </div>
            <div class="editor-field">
                @Html.DropDownList("selectedYear", null, "Vyberte rok", new { onchange = "this.form.submit();" })
            </div>
        </div>
    
        <div class="filter-item">
            <div class="editor-label">
                Mesiac
            </div>
            <div class="editor-field">
                @Html.DropDownList("selectedMonth", null, "Vyberte mesiac", new { onchange = "this.form.submit();" })
            </div>
        </div>

    </div>
}

<p></p>

@if (Model.Count() > 0)
{
    <table class="footable table toggle-arrow-tiny">
        <thead>
            <tr>
                <th width="100px" data-class="expand" data-type="numeric" data-sort-initial="ascending">
                    Dátum
                </th>
                <th>
                    Názov
                </th>
                <th>
                    Mesto
                </th>
                <th data-hide="phone,tablet">
                    Organizátor
                </th>
                <th width="60px" data-sort-ignore="true"></th>
                <th width="60px" data-sort-ignore="true"></th>
                <th width="60px" data-sort-ignore="true"></th>
                <th width="60px" data-sort-ignore="true"></th>
            </tr>
        </thead>
        <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td align="right">
                    @Html.DisplayFor(modelItem => item.DateFrom)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.City)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Organiser)
                </td>
                <!-- WEB -->
                <td align="center">
                    @if (!string.IsNullOrEmpty(item.Website))
                    {
                        string sAdress = "http://" + item.Website;
                        <a href="@sAdress" target="_blank">Web</a> 
                    }
                </td>

                <!-- PROPOZICIE -->
                <td align="center">
                    @if (item != null)
                    {
                        if(item.bPropositions)
                        {
                        string sResultPath = System.IO.Path.Combine(item.DateFrom.Value.Year.ToString(), item.DateFrom.Value.Month.ToString(), "PROP" + item.ID.ToString() + ".pdf");
                        <a href="@Url.Content("~/Content/results/" + @sResultPath)" target="_blank">
                            Propozície
                        </a>
                        }
                    }
                </td>                    
                        
                @{
                    DateTime today = DateTime.Now.Date;
                    if (item.DateFrom.Value.Date > today.Date)
                    {
                        <!-- VYSLEDKY -->
                        <td></td>
                    
                        <!-- PRILOHY -->
                        <td align="center">
                        <!-- Nasledujuce -->
                        @if (!string.IsNullOrEmpty(item.PreAttachments))
                        {
                            if(item.PreAttachments.StartsWith("www"))
                            {
                                string link = "http://" + @item.PreAttachments;
                                <a href="@link" target="_blank">
                                    Prihlášky
                                </a>
                            }
                            else
                            {
                                <a href="@Url.Content("~/Content/attachments/pre/" + @item.PreAttachments)" target="_blank">
                                    Prílohy
                                </a>
                            }
                        }
                        </td>
                        
                    }
                    else
                    {
                        <!-- VYSLEDKY -->
                        <td align="center">
                            @if (item.External)
                            {
                                if (item.bResults)
                                {
                                    string sResultPath = System.IO.Path.Combine(item.DateFrom.Value.Year.ToString(), item.DateFrom.Value.Month.ToString(), "VYS" + item.ID.ToString() + ".pdf");
                                <a href="@Url.Content("~/Content/results/" + @sResultPath)" target="_blank">
                                    Výsledky
                                </a>
                                }
                            }
                            else
                            { 
                                @Html.ActionLink("Výsledky", "Details", new { competitionId = item.ID })
                            }
                        </td>
                        
                        <!-- PRILOHY -->
                        <td align="center">
                            @if (!string.IsNullOrEmpty(item.PostAttachments))
                            {
                                <a href="@Url.Content("~/Content/attachments/post/" + @item.PostAttachments)" target="_blank">
                                    Prílohy
                                </a>
                            }
                        </td>
                    }
                }   
                
            </tr>
        }
        </tbody>
    </table>
    
    <p>
        @Html.Label("Počet záznamov: " + Model.Count().ToString())
    </p>
}

 